import axios from '@/utils/Request'
// import Vue from 'vue'
// import Vuex from 'vuex'
// Vue.use(Vuex)
// 1.创建store/index.js  并导入 createStore 方法
import { createStore } from 'vuex'

// 2.创建 store 仓库并导出
//   简写：export default createStore({ ...配置项 })
const stores = createStore({
  // 配置（state|mutations|actions|getters|modules）
  state: {
    arr: [] //渲染数据信息类别
    // detailspage:{},//详情页
  },
  getters: {},
  mutations: {
    Setarr(state: { arr: any[] }, { payload, Refresh }: any) {
      //下拉上拉  渲染
      if (Refresh) {
        state.arr = [...state.arr, ...payload]
      } else {
        state.arr = payload
      }
    }
    // appShop(state,payload){//详情啊
    //   state.detailspage=state.arr.find((item)=>item.id === payload)
    // },
  },
  actions: {
    Get_action({ commit, state }: any, payload: any) {
      axios.get('/list').then((data) => {
        commit({
          type: 'Setarr',
          payload: data.data.data,
          Refresh: payload
        })
      })
    }
  },
  modules: {}
})
export default stores
